<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="180px">
    <el-form-item label="批次号" prop="batchNumber">
      <el-input v-model="dataForm.batchNumber" placeholder="批次号"></el-input>
    </el-form-item>
    <el-form-item label="进件状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="进件状态"></el-input>
    </el-form-item>
    <el-form-item label="提交次数，默认为0" prop="requestCount">
      <el-input v-model="dataForm.requestCount" placeholder="提交次数，默认为0"></el-input>
    </el-form-item>
    <el-form-item label="提交时间" prop="requestTime">
      <el-date-picker
        v-model="dataForm.requestTime"
        type="datetime"
        placeholder="选择提交时间"
        format="yyyy-MM-dd HH:mm:ss"
        value-format="timestamp">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="姓名" prop="name">
      <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="用户手机号码" prop="mobilePhone">
      <el-input v-model="dataForm.mobilePhone" placeholder="用户手机号码" type="text" show-word-limit maxlength="11"></el-input>
    </el-form-item>
    <el-form-item label="城市" prop="city">
      <el-input v-model="dataForm.city" placeholder="城市"></el-input>
    </el-form-item>
    <el-form-item label="获客渠道" prop="channel">
      <el-input v-model="dataForm.channel" placeholder="获客渠道"></el-input>
    </el-form-item>
    <el-form-item label="名单来源" prop="channelSource">
      <el-input v-model="dataForm.channelSource" placeholder="名单来源"></el-input>
    </el-form-item>
    <el-form-item label="获客标签" prop="label">
      <el-input v-model="dataForm.label" placeholder="获客标签"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="gender">
      <el-input v-model="dataForm.gender" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="身份证号码" prop="idNumber">
      <el-input v-model="dataForm.idNumber" placeholder="身份证号码" type="text" show-word-limit maxlength="18"></el-input>
    </el-form-item>
    <el-form-item label="生日" prop="birthDay">
      <el-date-picker
        v-model="dataForm.birthDay"
        type="date"
        placeholder="选择出生日期"
        format="yyyy-MM-dd"
        value-format="timestamp">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="是否购房" prop="isHouse">
      <el-select v-model="dataForm.isHouse" placeholder="请选择">
        <el-option
          v-for="item in commonBool"
          :key="item.key"
          :label="item.value"
          :value="item.key">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="购房时间" prop="housingBuyPeriod">
      <el-input v-model="dataForm.housingBuyPeriod" placeholder="购房时间"></el-input>
    </el-form-item>
    <el-form-item label="月收入" prop="monthIncome">
      <el-input-number v-model="dataForm.monthIncome" :min="0" :max="1000000" placeholder="月收入"></el-input-number>
    </el-form-item>
    <el-form-item label="是否购车" prop="carStatus">
      <el-select v-model="dataForm.carStatus" placeholder="请选择">
        <el-option
          v-for="item in commonBool"
          :key="item.key"
          :label="item.value"
          :value="item.key">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="车辆是否抵押" prop="carPledgeStatus">
      <el-select v-model="dataForm.carPledgeStatus" placeholder="请选择">
        <el-option
          v-for="item in commonBool"
          :key="item.key"
          :label="item.value"
          :value="item.key">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="平安寿险情况" prop="paInsuranceType">
      <el-input v-model="dataForm.paInsuranceType" placeholder="平安寿险情况"></el-input>
    </el-form-item>
    <el-form-item label="公积金最近连续缴纳月数" prop="depositPeriod">
      <el-input-number v-model="dataForm.depositPeriod" :min="0" :max="360" placeholder="公积金最近连续缴纳月数"></el-input-number>
    </el-form-item>
    <el-form-item label="响应内容" prop="response">
      <el-input v-model="dataForm.response" placeholder="响应内容"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        commonBool: window.ENUMS['COMMON_BOOL'],
        genders: window.ENUMS['GENDER'],
        dataForm: {
          id: 0,
          batchNumber: '',
          status: '',
          requestCount: '',
          requestTime: '',
          name: '',
          mobilePhone: '',
          city: '',
          channel: '',
          channelSource: '',
          label: '',
          gender: '',
          idNumber: '',
          birthDay: '',
          age: '',
          isHouse: '',
          housingBuyPeriod: '',
          monthIncome: '',
          carStatus: '',
          carPledgeStatus: '',
          paInsuranceType: '',
          depositPeriod: '',
          response: '',
          createUserId: '',
          createTime: ''
        },
        dataRule: {
          batchNumber: [
            { required: true, message: '批次号不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '进件状态不能为空', trigger: 'blur' }
          ],
          requestCount: [
            { required: true, message: '提交次数，默认为0不能为空', trigger: 'blur' }
          ],
          requestTime: [
            { required: true, message: '提交时间不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          mobilePhone: [
            { required: true, message: '用户手机号码不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '城市不能为空', trigger: 'blur' }
          ],
          channel: [
            { required: true, message: '获客渠道不能为空', trigger: 'blur' }
          ],
          channelSource: [
            { required: true, message: '名单来源不能为空', trigger: 'blur' }
          ],
          label: [
            { required: true, message: '获客标签不能为空', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          idNumber: [
            { required: true, message: '身份证号码不能为空', trigger: 'blur' }
          ],
          birthDay: [
            { required: true, message: '生日不能为空', trigger: 'blur' }
          ],
          age: [
            { required: true, message: '年龄不能为空', trigger: 'blur' }
          ],
          isHouse: [
            { required: true, message: '是否购房不能为空', trigger: 'blur' }
          ],
          housingBuyPeriod: [
            { required: true, message: '购房时间不能为空', trigger: 'blur' }
          ],
          monthIncome: [
            { required: true, message: '月收入不能为空', trigger: 'blur' }
          ],
          paInsuranceType: [
            { required: true, message: '平安寿险情况不能为空', trigger: 'blur' }
          ],
          depositPeriod: [
            { required: true, message: '公积金最近连续缴纳月数不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/customer/batchapplication/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.batchNumber = data.batchApplication.batchNumber
                this.dataForm.status = data.batchApplication.status
                this.dataForm.requestCount = data.batchApplication.requestCount
                this.dataForm.requestTime = data.batchApplication.requestTime
                this.dataForm.name = data.batchApplication.name
                this.dataForm.mobilePhone = data.batchApplication.mobilePhone
                this.dataForm.city = data.batchApplication.city
                this.dataForm.channel = data.batchApplication.channel
                this.dataForm.channelSource = data.batchApplication.channelSource
                this.dataForm.label = data.batchApplication.label
                this.dataForm.gender = data.batchApplication.gender
                this.dataForm.idNumber = data.batchApplication.idNumber
                this.dataForm.birthDay = data.batchApplication.birthDay
                this.dataForm.age = data.batchApplication.age
                this.dataForm.isHouse = data.batchApplication.isHouse
                this.dataForm.housingBuyPeriod = data.batchApplication.housingBuyPeriod
                this.dataForm.monthIncome = data.batchApplication.monthIncome
                this.dataForm.carStatus = data.batchApplication.carStatus
                this.dataForm.carPledgeStatus = data.batchApplication.carPledgeStatus
                this.dataForm.paInsuranceType = data.batchApplication.paInsuranceType
                this.dataForm.depositPeriod = data.batchApplication.depositPeriod
                this.dataForm.response = data.batchApplication.response
                this.dataForm.createUserId = data.batchApplication.createUserId
                this.dataForm.createTime = data.batchApplication.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/customer/batchapplication/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'batchNumber': this.dataForm.batchNumber,
                'status': this.dataForm.status,
                'requestCount': this.dataForm.requestCount,
                'requestTime': this.dataForm.requestTime,
                'name': this.dataForm.name,
                'mobilePhone': this.dataForm.mobilePhone,
                'city': this.dataForm.city,
                'channel': this.dataForm.channel,
                'channelSource': this.dataForm.channelSource,
                'label': this.dataForm.label,
                'gender': this.dataForm.gender,
                'idNumber': this.dataForm.idNumber,
                'birthDay': this.dataForm.birthDay,
                'age': this.dataForm.age,
                'isHouse': this.dataForm.isHouse,
                'housingBuyPeriod': this.dataForm.housingBuyPeriod,
                'monthIncome': this.dataForm.monthIncome,
                'carStatus': this.dataForm.carStatus,
                'carPledgeStatus': this.dataForm.carPledgeStatus,
                'paInsuranceType': this.dataForm.paInsuranceType,
                'depositPeriod': this.dataForm.depositPeriod,
                'response': this.dataForm.response,
                'createUserId': this.dataForm.createUserId,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
